# 指定CMake的最低版本要求
cmake_minimum_required(VERSION 3.16)

# 项目名称
project(Qt5Demo VERSION 1.0.0 LANGUAGES CXX)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找Qt5包
find_package(Qt5 COMPONENTS Widgets Core Gui REQUIRED)

# 自动处理Qt的MOC、UIC和RCC文件
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# 添加源文件
set(SOURCES
    main.cpp
    mainwindow.cpp
    mywidget.cpp
)

# 添加头文件
set(HEADERS
    mainwindow.h
    mywidget.h
)

# 创建可执行文件
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})

# 链接Qt库
target_link_libraries(${PROJECT_NAME} PRIVATE
    Qt5::Widgets
    Qt5::Core
    Qt5::Gui
)

# 设置输出路径
set_target_properties(${PROJECT_NAME} PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

# 安装配置（可选）
install(TARGETS ${PROJECT_NAME}
    RUNTIME DESTINATION bin
)